package day07.util;

import com.alibaba.fastjson.JSON;
import day07.util.Serializer;
import day07.util.SerializerAlgorithm;

/**
 * @author chenshijie
 * @date 2023/12/20 14:40
 */

public class JSONSerializer implements Serializer {
    @Override
    public byte getSerializerAlgorithm() {
        return SerializerAlgorithm.JSON;
    }

    @Override
    public byte[] serialize(Object object) {
        return JSON.toJSONBytes(object);
    }

    @Override
    public <T> T deserialize(Class<T> clazz, byte[] bytes) {
        return JSON.parseObject(bytes, clazz);
    }
}
